home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kdesu / client.h next >
Encoding:
C/C++ Source or Header  |  2005-09-10  |  5.7 KB  |  208 lines

  1. /* vi: ts=8 sts=4 sw=4
  2.  *
  3.  * $Id$
  4.  *
  5.  * This file is part of the KDE project, module kdesu.
  6.  * Copyright (C) 1999,2000 Geert Jansen <jansen@kde.org>
  7.  *
  8.  * This is free software; you can use this library under the GNU Library
  9.  * General Public License, version 2. See the file "COPYING.LIB" for the
  10.  * exact licensing terms.
  11.  *
  12.  * client.h: client to access kdesud.
  13.  */
  14.  
  15. #ifndef __KDE_su_Client_h_Included__
  16. #define __KDE_su_Client_h_Included__
  17.  
  18. #include <qglobal.h>
  19. #include <kdelibs_export.h>
  20.  
  21. #ifdef Q_OS_UNIX
  22.  
  23. #include <sys/types.h>
  24. #include <sys/socket.h>
  25. #include <sys/un.h>
  26.  
  27. #include <qcstring.h>
  28. #include <qvaluelist.h>
  29.  
  30. typedef QValueList<QCString> QCStringList;
  31.  
  32. /**
  33.  * A client class to access kdesud, the KDE su daemon. Kdesud can assist in 
  34.  * password caching in two ways:
  35.  *
  36.  * @li For high security passwords, like for su and ssh, it executes the
  37.  * password requesting command for you. It feeds the password to the
  38.  * command, without ever returning it to you, the user. The daemon should 
  39.  * be installed setgid nogroup, in order to be able to act as an inaccessible, 
  40.  * trusted 3rd party. 
  41.  * See exec, setPass, delCommand.
  42.  *
  43.  * @li For lower security passwords, like web and ftp passwords, it can act
  44.  * as a persistent storage for string variables. These variables are
  45.  * returned to the user, and the daemon doesn't need to be setgid nogroup
  46.  * for this.
  47.  * See setVar, delVar, delGroup.
  48.  */
  49.  
  50. class KDESU_EXPORT KDEsuClient {
  51. public:
  52.     KDEsuClient();
  53.     ~KDEsuClient();
  54.  
  55.     /**
  56.      * Lets kdesud execute a command. If the daemon does not have a password
  57.      * for this command, this will fail and you need to call setPass().
  58.      *
  59.      * @param command The command to execute.
  60.      * @param user The user to run the command as.
  61.      * @param options Extra options.
  62.      * @param env Extra environment variables.
  63.      * @return Zero on success, -1 on failure.
  64.      */
  65.     int exec(const QCString &command, const QCString &user, const QCString &options=0, const QCStringList &env=QCStringList());
  66.  
  67.     /**
  68.      * Wait for the last command to exit and return the exit code.
  69.      * @return Exit code of last command, -1 on failure.
  70.      */
  71.     int exitCode();
  72.  
  73.     /**
  74.      * Set root's password, lasts one session.
  75.      *
  76.      * @param pass Root's password.
  77.      * @param timeout The time that a password will live.
  78.      * @return Zero on success, -1 on failure.
  79.      */
  80.     int setPass(const char *pass, int timeout);
  81.  
  82.     /**
  83.      * Set the target host (optional).
  84.      */
  85.     int setHost(const QCString &host);
  86.  
  87.     /**
  88.      * Set the desired priority (optional), see StubProcess.
  89.      */
  90.     int setPriority(int priority);
  91.  
  92.     /**
  93.      * Set the desired scheduler (optional), see StubProcess.
  94.      */
  95.     int setScheduler(int scheduler);
  96.  
  97.     /**
  98.      * Remove a password for a user/command.
  99.      * @param command The command.
  100.      * @param user The user.
  101.      * @return zero on success, -1 on an error
  102.      */
  103.     int delCommand(const QCString &command, const QCString &user);
  104.  
  105.     /**
  106.      * Set a persistent variable.
  107.      * @param key The name of the variable.
  108.      * @param value Its value.
  109.      * @param timeout The timeout in seconds for this key. Zero means
  110.      * no timeout.
  111.      * @param group Make the key part of a group. See delGroup.
  112.      * @return zero on success, -1 on failure.
  113.      */
  114.     int setVar(const QCString &key, const QCString &value, int timeout=0, const QCString &group=0);
  115.  
  116.     /**
  117.      * Get a persistent variable.
  118.      * @param key The name of the variable.
  119.      * @return Its value.
  120.      */
  121.     QCString getVar(const QCString &key);
  122.  
  123.     /**
  124.      * Gets all the keys that are membes of the given group.
  125.      * @param group the group name of the variables.
  126.      * @return a list of the keys in the group.
  127.      */
  128.     QValueList<QCString> getKeys(const QCString &group);
  129.  
  130.     /**
  131.      * Returns true if the specified group exists is
  132.      * cached.
  133.      *
  134.      * @param group the group key
  135.      * @return true if the group is found
  136.      */
  137.     bool findGroup(const QCString &group);
  138.  
  139.     /**
  140.      * Delete a persistent variable.
  141.      * @param key The name of the variable.
  142.      * @return zero on success, -1 on failure.
  143.      */
  144.     int delVar(const QCString &key);
  145.  
  146.     /**
  147.      * Delete all persistent variables with the given key.
  148.      *
  149.      * A specicalized variant of delVar(QCString) that removes all
  150.      * subsets of the cached varaibles given by @p key. In order for all
  151.      * cached variables related to this key to be deleted properly, the
  152.      * value given to the @p group argument when the setVar function
  153.      * was called, must be a subset of the argument given here and the key
  154.      *
  155.      * @note Simply supplying the group key here WILL not necessarily
  156.      * work. If you only have a group key, then use delGroup instead.
  157.      *
  158.      * @param special_key the name of the variable.
  159.      * @return zero on success, -1 on failure.
  160.      */
  161.     int delVars(const QCString &special_key);
  162.  
  163.     /**
  164.      * Delete all persistent variables in a group.
  165.      *
  166.      * @param group the group name. See setVar.
  167.      * @return
  168.      */
  169.     int delGroup(const QCString &group);
  170.  
  171.     /**
  172.      * Ping kdesud. This can be used for diagnostics.
  173.      * @return Zero on success, -1 on failure
  174.      */
  175.     int ping();
  176.  
  177.     /**
  178.      * Stop the daemon.
  179.      */
  180.     int stopServer();
  181.  
  182.     /**
  183.      * Try to start up kdesud
  184.      */
  185.     int startServer();
  186.  
  187.     /**
  188.      * Returns true if the server is safe (installed setgid), false otherwise.
  189.      */
  190.     bool isServerSGID();
  191.  
  192. private:
  193.     int connect();
  194.  
  195.     int sockfd;
  196.     QCString sock;
  197.  
  198.     int command(const QCString &cmd, QCString *result=0L);
  199.     QCString escape(const QCString &str);
  200.  
  201.     class KDEsuClientPrivate;
  202.     KDEsuClientPrivate *d;
  203. };
  204.  
  205. #endif //Q_OS_UNIX
  206.  
  207. #endif //__KDE_su_Client_h_Included__
  208.